#!/usr/bin/python3
# -*- coding: utf-8; tab-width: 4; indent-tabs-mode: t -*-

import abc
import enum


class EventType(enum.Enum):
    INIT = "init"                                                              # shared stage
    INTERFACE_APPEARED = "interface-appeared"                                  # exclusive stage
    INTERFACE_DHCP_SERVER_APPEARED = "interface-dhcp-server-appeared"          # exclusive stage
    INTERFACE_DHCP_SERVER_DISAPPREARED = "interface-dhcp-server-disappeared"   # exclusive stage
    INTERFACE_WIFI_SSID_APPEARED = "interface-wifi-ssid-appeared"              # exclusive stage
    INTERFACE_WIFI_SSID_DISAPPEARED = "interface-wifi-ssid-disappeared"        # exclusive stage
    INTERFACE_DISAPPEARED = "interface-disappeared"                            # exclusive stage
    CONNECTION_ACTIVATED = "connection-activated"                              # shared stage
    CONNECTION_DEACTIVATED = "connection-deactivated"                          # shared stage
    OUT_CHANGED = "out-changed"                                                # shared stage
    GEOLOCATION_CHANGED = "geolocation-changed"                                # shared stage
    DISPOSE = "dispose"


class EventBase(abc.ABC):

    @property
    def event_type(self):
        if isinstance(self, EventInit):
            return EventType.INIT
        elif isinstance(self, EventInterfaceAppeared):
            return EventType.INTERFACE_APPEARED
        elif isinstance(self, EventInterfaceDhcpServerAppeared):
            return EventType.INTERFACE_DHCP_SERVER_APPEARED
        elif isinstance(self, EventInterfaceDhcpServerDisappeared):
            return EventType.INTERFACE_DHCP_SERVER_DISAPPREARED
        elif isinstance(self, EventInterfaceWifiSsidAppeared):
            return EventType.INTERFACE_WIFI_SSID_APPEARED
        elif isinstance(self, EventInterfaceWifiSsidDisappeared):
            return EventType.INTERFACE_WIFI_SSID_DISAPPEARED
        elif isinstance(self, EventInterfaceDisappeared):
            return EventType.INTERFACE_DISAPPEARED
        elif isinstance(self, EventObConnActivated):
            return EventType.CONNECTION_ACTIVATED
        elif isinstance(self, EventObConnDeactivated):
            return EventType.CONNECTION_DEACTIVATED
        elif isinstance(self, EventOutChanged):
            return EventType.OUT_CHANGED
        elif isinstance(self, EventGeolocationChanged):
            return EventType.GEOLOCATION_CHANGED
        elif isinstance(self, EventDispose):
            return EventType.DISPOSE
        else:
            assert False


class EventInit(EventBase):
    pass


class EventInterfaceAppeared(EventBase):

    def __init__(self, interface_name):
        self._ifname = interface_name

    @property
    def interface_name(self):
        return self._ifname


class EventInterfaceDhcpServerAppeared(EventBase):

    def __init__(self, interface_name, dhcp_server_mac_address):
        self._ifname = interface_name
        self._serverMac = dhcp_server_mac_address

    @property
    def interface_name(self):
        return self._ifname

    @property
    def dhcp_server_mac_address(self):
        return self._serverMac


class EventInterfaceDhcpServerDisappeared(EventBase):

    def __init__(self, interface_name, dhcp_server_mac_address):
        self._ifname = interface_name
        self._serverMac = dhcp_server_mac_address

    @property
    def interface_name(self):
        return self._ifname

    @property
    def dhcp_server_mac_address(self):
        return self._serverMac


class EventInterfaceWifiSsidAppeared(EventBase):

    def __init__(self, interface_name, ssid, bssid):
        self._ifname = interface_name
        self._ssid = ssid
        self._bssid = bssid

    @property
    def interface_name(self):
        return self._ifname

    @property
    def ssid(self):
        return self._ssid
    
    @property
    def bssid(self):
        return self._bssid


class EventInterfaceWifiSsidDisappeared(EventBase):

    def __init__(self, interface_name, ssid, bssid):
        self._ifname = interface_name
        self._ssid = ssid
        self._bssid = bssid

    @property
    def interface_name(self):
        return self._ifname

    @property
    def ssid(self):
        return self._ssid
    
    @property
    def bssid(self):
        return self._bssid


class EventInterfaceDisappeared(EventBase):

    def __init__(self, interface_name):
        self._ifname = interface_name

    @property
    def interface_name(self):
        return self._ifname


class EventObConnActivated(EventBase):

    def __init__(self, connection_object):
        self._conn = connection_object

    @property
    def connection_object(self):
        return self._conn


class EventObConnDeactivated(EventBase):

    def __init__(self, connection_uuid):
        self._uuid = connection_uuid

    @property
    def connection_uuid(self):
        return self._uuid


class EventOutChanged(EventBase):
    pass


class EventGeolocationChanged(EventBase):

    def __init__(self, latitude, longitude):
        self._latitude = latitude
        self._longitude = longitude

    @property
    def latitude(self):
        return self._latitude
    
    @property
    def longitude(self):
        return self._longitude


class EventDispose(EventBase):
    pass
